package net.xdclass.listener;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import net.xdclass.enums.BizCodeEnum;
import net.xdclass.exception.BizException;
import net.xdclass.model.EventMessage;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author ：zhouyang
 * @date ：Created in 2022/5/12 12:48
 * @modified By：
 * @version: $
 */
@Component
@Slf4j
@RabbitListener(queuesToDeclare = { @Queue("short_link.error.queue") })
public class ShortLinkErrorMQListener {

    @RabbitHandler
    public void shortLinkHandler(EventMessage eventMessage, Message message, Channel channel) throws IOException {
        log.error("警告：监听到消息ShortLinkErrorMQListener：message消息内容：{}", eventMessage);
        log.error("警告：{}", message);
        log.error("警告成功，发送短信");
        long tag = message.getMessageProperties().getDeliveryTag();
        try {

        } catch (Exception e) {
            e.printStackTrace();
            log.error("消费失败:{}", eventMessage);
            throw new BizException(BizCodeEnum.MQ_CONSUME_EXCEPTION);
        }
        log.info("消费成功:{}", eventMessage);
        //确认消息消费成功
//        channel.basicAck(tag, false);
    }
}
